package javolution.text;

import com.alibaba.fastjson.parser.JSONLexer;
import javolution.lang.Immutable;
import javolution.lang.MathLib;
import kotlin.text.Typography;

/* loaded from: classes2.dex */
public final class CharSet implements Immutable {
    private final long[] _mapping;
    public static final CharSet EMPTY = new CharSet(new long[0]);
    public static final CharSet WHITESPACES = valueOf('\t', '\n', 11, '\f', '\r', 28, 29, 30, 31, ' ', 5760, 6158, 8192, 8193, 8194, 8195, 8196, 8197, 8198, 8200, 8201, 8202, 8203, 8232, 8233, 8287, 12288);
    public static final CharSet SPACES = valueOf(' ', Typography.nbsp, 5760, 6158, 8192, 8193, 8194, 8195, 8196, 8197, 8198, 8199, 8200, 8201, 8202, 8203, 8232, 8233, 8239, 8287, 12288);
    public static final CharSet ISO_CONTROLS = valueOf(0, 1, 2, 3, 4, 5, 6, 7, '\b', '\t', '\n', 11, '\f', '\r', 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, JSONLexer.EOI, 27, 28, 29, 30, 31, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159);

    private CharSet(long[] jArr) {
        this._mapping = jArr;
    }

    private CharSet copy() {
        CharSet charSet = new CharSet(new long[this._mapping.length]);
        int length = this._mapping.length;
        while (true) {
            length--;
            if (length < 0) {
                return charSet;
            }
            charSet._mapping[length] = this._mapping[length];
        }
    }

    public static CharSet rangeOf(char c, char c2) {
        if (c <= c2) {
            CharSet charSet = new CharSet(new long[(c2 >> 6) + 1]);
            while (c <= c2) {
                long[] jArr = charSet._mapping;
                int i = c >> 6;
                jArr[i] = jArr[i] | (1 << (c & '?'));
                c = (char) (c + 1);
            }
            return charSet;
        }
        throw new IllegalArgumentException("first should be less or equal to last");
    }

    public static CharSet valueOf(char... cArr) {
        int length = cArr.length;
        char c = 0;
        while (true) {
            length--;
            if (length < 0) {
                break;
            } else if (cArr[length] > c) {
                c = cArr[length];
            }
        }
        CharSet charSet = new CharSet(new long[(c >> 6) + 1]);
        int length2 = cArr.length;
        while (true) {
            length2--;
            if (length2 < 0) {
                return charSet;
            }
            char c2 = cArr[length2];
            long[] jArr = charSet._mapping;
            int i = c2 >> 6;
            jArr[i] = jArr[i] | (1 << (c2 & '?'));
        }
    }

    public boolean contains(char c) {
        int i = c >> 6;
        long[] jArr = this._mapping;
        return i < jArr.length && (jArr[i] & (1 << (c & '?'))) != 0;
    }

    public CharSet minus(CharSet charSet) {
        CharSet copy = copy();
        int min = MathLib.min(this._mapping.length, charSet._mapping.length);
        while (true) {
            min--;
            if (min < 0) {
                return copy;
            }
            long[] jArr = copy._mapping;
            jArr[min] = jArr[min] & (charSet._mapping[min] ^ (-1));
        }
    }

    public CharSet plus(CharSet charSet) {
        if (charSet._mapping.length > this._mapping.length) {
            return charSet.plus(this);
        }
        CharSet copy = copy();
        int length = charSet._mapping.length;
        while (true) {
            length--;
            if (length < 0) {
                return copy;
            }
            long[] jArr = copy._mapping;
            jArr[length] = jArr[length] | charSet._mapping[length];
        }
    }

    public String toString() {
        TextBuilder newInstance = TextBuilder.newInstance();
        newInstance.append('{');
        int length = this._mapping.length << 6;
        for (int i = 0; i < length; i++) {
            char c = (char) i;
            if (contains(c)) {
                if (newInstance.length() > 1) {
                    newInstance.append(',');
                    newInstance.append(' ');
                }
                newInstance.append('\'');
                newInstance.append(c);
                newInstance.append('\'');
            }
        }
        newInstance.append('}');
        return newInstance.toString();
    }
}
